package com.stone.framework.task.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.stone.framework.message.PageReqMessage;
import com.stone.framework.message.PageResMessage;
import com.stone.framework.message.ReqMessage;
import com.stone.framework.message.ResMessage;
import com.stone.framework.message.task.JobExecutionPageReqBody;
import com.stone.framework.message.task.JobExecutionPageResBody;
import com.stone.framework.message.task.StepExecutionResBody;
import com.stone.framework.task.service.ExecutionService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "执行历史")
@RestController
@RequestMapping("/execution")
public class ExecutionController {

    @Autowired
    private ExecutionService executionService;

    @ApiOperation(value = "job列表", httpMethod = "POST")
    @PostMapping(value = "/job/getPage")
    PageResMessage<JobExecutionPageResBody>
        getJobPage(@Valid @RequestBody PageReqMessage<JobExecutionPageReqBody> reqMessage) {
        IPage<JobExecutionPageResBody> page =
            executionService.queryJobPage(reqMessage.getBody(), reqMessage.buildPage());
        return PageResMessage.success(page);
    }

    @ApiOperation(value = "step列表", httpMethod = "POST")
    @PostMapping(value = "/step/getList")
    ResMessage<List<StepExecutionResBody>> getStepList(@Valid @RequestBody ReqMessage<Long> reqMessage) {
        List<StepExecutionResBody> list = executionService.queryStepList(reqMessage.getBody());
        return ResMessage.success(list);
    }

}
